﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class FollowupAudition
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            HttpSessionState session =System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Type = "FollowupAudition";
            pg.SMenuId = "KH";
            pg.TableName = "cu_Cus_followup";
            pg.KeyFieldName = "id";
            pg.Sop = BasePage.Grant(session, pg.SMenuId);            
            pg.Sop.BROWSE = BasePage.Grant(session, pg.SMenuId, "GJ");
            pg.Sop.ADD = pg.Sop.EDIT = pg.Sop.DEL = false;
                       
            String id = "0";
            HttpRequest request = System.Web.HttpContext.Current.Request;
            if (request["Ids"] != null) id = Fun.cSql(request["Ids"]);

            String button = "";
            //未试听 未收费
            button += "<a href=\"javascript:ShowModalUrl('popEdit', '../Account/At?id=-1&FlowingType=00104001&cid=" + id + "&accountId=[accountId]&followupId=[id]&keyCode='+ GetKeyCode('[id]'), '收费', '', '', '') \"  class='layui-btn layui-btn-xs layui-btn-normal' style='display:[btn1Show]'>收费</a>";
            //未试听 已收费 未入账=》删除流水且收费状态改0
            button += "<a href =\"javascript: layer.confirm('您确定要退费吗？', function (index) {layer.close(index);Do('../Customer/FollowupList/AuditionReturn',{ id:[id],keyCode: GetKeyCode('[id]')},true);})\"  class='layui-btn layui-btn-xs layui-btn-danger' style='display:[btn2Show]'>退费</a>"; 
            //未试听 已收费 已入账=》退费操作
            button += "<a href=\"javascript:ShowModalUrl('popEdit', '../Account/At?id=-1&FlowingType=00204001&cid=" + id + "&accountId=[accountId]&followupId=[id]&keyCode='+ GetKeyCode('[id]'), '退费', '', '', '') \"  class='layui-btn layui-btn-xs layui-btn-danger' style='display:[btn3Show]'>退费</a>";


            pg.Sql = String.Format(@"select t1.*,
    t2.id as accountId,t2.AcNumber,t2.Account,t4.dname as AccountModeCn,t2.remark as AccountRemark,t5.dname as AccountStateCn,t6.dname as IsChargeCn,
    case when courseState=0 and isCharge=0 then 'inline-block' else 'none' end as btn1Show,
    case when courseState=0 and isCharge=1 and t2.state=0 then 'inline-block' else 'none' end as btn2Show,
    case when courseState=0 and isCharge=1 and t2.state=2 and isnull(t2.isReturn,0)=0 then 'inline-block' else 'none' end as btn3Show,
	t3.CourseName,case when CourseState=1 then '已试听' else '未试听' end CourseStateCn,'' link
from cu_Cus_followup t1
left join cu_Account t2 on t1.id=t2.FollowupId
left join cu_Course t3 on t1.CourseId=t3.id
left join tb_sys_dictionary t4 on t2.AccountMode=t4.did and t4.typeid='D16'
left join tb_sys_dictionary t5 on t2.state=t5.did and t5.typeid='D14'
left join tb_sys_dictionary t6 on t1.isCharge=t6.did and t6.typeid='D06'
where t1.IsAuditions=1 and t1.cid={0}", id);
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.DataType = Tag.Date; cl.FieldName = "makeDate"; cl.HeadText = "预约时间"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "CourseName"; cl.HeadText = "试听课程"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "CourseStateCn"; cl.HeadText = "试听状态";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "IsChargeCn"; cl.HeadText = "收费状态"; pg.AddColumn(cl);

            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "AcNumber"; cl.HeadText = "收费编号"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "Account"; cl.HeadText = "收费金额";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "AccountModeCn"; cl.HeadText = "收费方式";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "AccountRemark"; cl.HeadText = "收费备注";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "AccountStateCn"; cl.HeadText = "入账状态"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; cl.Script = button; pg.AddColumn(cl);
            return pg;
        }
    }
}